
<template>
  <div>
    <Modal
      v-model="showBox"
      title="修改邮箱"
      :footer-hide="true"
      :mask-closable="false"
      @on-visible-change="vChange"
      width="500"
    >
      <div class="f_16 marginB20">用户手机：{{userPower.mobile}}</div>
      <Row class="marginB20" :gutter="20">
        <Col span="16">
          <Input type="number" placeholder="短信验证码" v-model="code" ref="code" clearable size="large"
          onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
          >
            <Icon type="ios-chatboxes" slot="prefix" />
          </Input>
        </Col>
        <Col span="8">
        <!-- button 倒计时函数，要用jq处理，原因细说 -->
          <Button
            type="primary"
            size="large"
            long
            @click="goCodeFun"
            :disabled="btnDisabled"
            id="eDom"
          >获取验证码</Button>
        </Col>
      </Row>

      <Input type="text" v-model.lazy="email" placeholder="请输入新的邮箱地址" ref="email" class="marginB20" size="large" clearable>
        <Icon type="md-mail" slot="prefix" />
      </Input>
      <Button type="primary" class="marginB10" size="large" long @click="goFun">确 定</Button>
    </Modal>
  </div>
</template>



<script>
export default {
  name: "emailSet",
  components: {},
  data() {
    return {
      // 弹框是否显示
      showBox: false,
      phoneOk: true,

      email: "",
      captcha: "", //图形 验证码
      code: "", //手机 验证码

      // 获取验证码按钮
      btnDisabled: false
    };
  },
  props:['userPower','companyAll'],
  watch:{
    userPower(newVal,oldVal){
      this.userPower=newVal;
    },
    companyAll(newVal,oldVal){
      this.companyAll=newVal;
    },
  },
  created(){},
  mounted() {},
  methods: {
    goCodeFun() {
      let that=this;
      let mobile=this.userPower.mobile;

      //2登录,3修改密码,4合伙人认证,5绑定邮箱
      $ajax.getCodeNn(that,'eDom',mobile,5);
    },
    //提交
    goFun() {
      let that=this;
      let {email,code}=that;
      if(!$app.judgeData(code)){
        that.$Message.error({content:'验证码不能为空'});
        that.$refs['code'].focus();
      }else if(!$app.judgeData(email)){
        that.$Message.error({content:'邮箱不能为空'});
        that.$refs['email'].focus();
      }else if(!$app.mailCheck(email)){
        that.$Message.error({content:'邮箱格式错误，勿含空格等特殊字符'});
        that.$refs['email'].focus();
      }else{
        $ajax.lb_getSendEmail(email,code,that,()=>{
          that.showBox=false;
          this.$emit('getData');//更新数据
        });
      }
    },

    //弹框消失
    vChange(buEr) {
      if(!buEr){
       
        this.email= "";
        this.captcha= ""; //图形 验证码
        this.code= ""; //手机 验证码
        
      }
    }
  }
};
</script>

<style>
</style>
